package com.fs.dao.Impl;

import com.fs.dao.NoticeDao;
import com.fs.pojo.Notice;
import com.fs.utils.JDBCUtils;

import java.util.List;

public class NoticeDaoImpl implements NoticeDao {

    @Override
    public Notice queryById(String id) {
        String sql = "select * from tb_notice where id = ?";

        List<Notice> list = JDBCUtils.executeQurey(sql, Notice.class, id);
        return list == null ? null : list.get(0) ;
    }

    @Override
    public List<Notice> queryAll() {
        String sql = "select * from tb_notice ";
        return JDBCUtils.executeQurey(sql,Notice.class);
    }

    @Override
    public int insert(Notice obj) {
        String sql = "insert tb_notice(id,class_id, title, content, time) values (?,?,?,?,?)";
        return JDBCUtils.executeUpdate(sql,obj.getId(),obj.getClassId(),obj.getTitle(),obj.getContent(),obj.getTime());

    }

    @Override
    public int deleteById(String id) {
        String sql = "delete from tb_notice where id=?";
        return JDBCUtils.executeUpdate(sql,id);

    }

    @Override
    public int update(Notice obj) {
        String sql = JDBCUtils.parseUpdateSQL(obj, "tb_notice");

        return JDBCUtils.executeUpdate(sql,obj);
    }

    @Override
    public List<Notice> queryByClass(String classId) {
        String sql = "select * from tb_notice where class_id = ?";

        return JDBCUtils.executeQurey(sql, Notice.class, classId);

    }

    @Override
    public List<Notice> queryByTitle(String title, String classId) {
        String sql = "select * from tb_notice where title like ?  and class_id = ?";
        return JDBCUtils.executeQurey(sql,Notice.class,"%"+title+"%",classId);
    }
}
